﻿using System;
using System.Windows;
using System.Windows.Shapes;
using System.Linq;
using System.Collections.Generic;

namespace PatternLockControl.Code
{
    public static class DrawExtension
    {
        /// <summary>
        /// Update line object 
        /// </summary>
        /// <param name="line">Line object</param>
        /// <param name="newSource">new start point</param>
        /// <param name="newDestination">new end point</param>
        public static void UpdateLine(this Line line, Point newSource, Point newDestination)
        {
            if (ReferenceEquals(null, newSource) || ReferenceEquals(null, newDestination))
                throw new ArgumentNullException("newSource or newDestination null argument exception");
            line.X1 = newSource.X;
            line.Y1 = newSource.Y;
            line.X2 = newDestination.X;
            line.Y2 = newDestination.Y;
        }
    }

    public static class DictionaryExtension
    {
        /// <summary>
        /// Compare IDictionary by references value
        /// </summary>
        /// <typeparam name="TKey">Key</typeparam>
        /// <typeparam name="TValue">Value</typeparam>
        /// <param name="source">Dictionary source</param>
        /// <param name="compare">Dictionary to compare</param>
        /// <returns></returns>
        public static bool EqualWithOrder<TKey, TValue>(this IDictionary<TKey, TValue> source, IDictionary<TKey, TValue> compare)
            where TValue : SquarePattern
        {
            if (null == source || null == compare)
                throw new ArgumentNullException("Argument");

            if (source.Count != compare.Count)
                return false;

            for (int i = 0; i < source.Count; ++i)
            {
                if (!ReferenceEquals(source.ElementAt(i).Value, compare.ElementAt(i).Value))
                {
                    return false;
                }
            }
            return true;
        }
    }
}
